﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Tb.App.API.Applicaions.Command.DeepProcessing;
using Tb.App.API.Applications.Command.DeepProcessing;
using Tb.App.Domain.Rabbit.DeepProcessing;
using Tb.App.ErrorCode;

namespace Tb.App.API.Controllers.Rabbit
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeeprocessingController : ControllerBase
    {
        private readonly ILogger<DeeprocessingController> logger;
        private readonly IMediator mediator;

        public DeeprocessingController(ILogger<DeeprocessingController> logger,IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加深加工信息
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回添加任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeeprocessing(AddDeeprocessingModelCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("添加深加工信息失败=>"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 深加工信息查询
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询任务</returns>
        [HttpGet]
        public async Task<ApiResult<DeepProcessingModel>> GetDeeprocessingModel([FromQuery]GetDeeprocessingModelCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("深加工信息加载失败=>"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 添加深加工企业信息
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回添加任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeepProcessingCompany(AddDeepProcessingCompanyCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("添加深加工企业信息失败=>" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 深加工企业信息查询
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询任务</returns>
        [HttpGet]
        public async Task<ApiResult<DeepProcessingCompany>> GetDeepProcessingCompanyQuery([FromQuery]GetDeepProcessingCompanyQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("深加工企业信息加载失败=>" + ex.Message);
                throw;
            }
        }
    }
}
